//
//  ObservableType+CBHandy.swift
//  Moya_Rx
//
//  Created by fst on 2019/12/26.
//  Copyright © 2019 fst. All rights reserved.
//

import Foundation
import RxSwift
import HandyJSON
import Moya

public extension ObservableType where Element == Response {

    func mapObject<T: HandyJSON>(_ type: T.Type) -> Observable<T> {
    return flatMap { response -> Observable<T> in
            return Observable.just(try response.mapObject(type))
        }
    }
    
    func mapArray<T: HandyJSON>(_ type: T.Type) -> Observable<[T]> {
        return flatMap { response -> Observable<[T]> in
                    return Observable.just(try response.mapArray(type))
       }
    }
}

